package com.cx.controller;

import com.cx.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/comment")
public class CommentController {


    @Autowired
    private CommentService contentService;

    //    查询全部评论
    @RequestMapping("/getCommentAll")
    public String getCommentAll(HttpServletRequest request) {
        System.out.println("=======getCommentAll========");
        request.setAttribute("commentList", contentService.getCommentAll());
        System.out.println(contentService.getCommentAll());
        return "comment";
    }

    //    留言管理查询个人评论全部
    @RequestMapping("/getCommentAllById")
    public String getCommentAll(Integer id, HttpServletRequest request) {
        System.out.println("=======getCommentAllById========");
        request.setAttribute("commentList", contentService.getCommentAllById(id));
        System.out.println(contentService.getCommentAllById(id));
        return "comment";
    }

    //    增
//    添加评论
    @RequestMapping("/addComment")
    public String addComment(Integer id, String content) {
        System.out.println("=======addComment========");
        contentService.addComment(id, content);
        return "redirect:/comment/getCommentAll";
    }

    //    添加评论回复
    @RequestMapping("/addCommentReply")
    public String addCommentReply(Integer id, String content, Integer pid) {
        System.out.println("=======addCommentReply========");
        contentService.addCommentReply(id, content, pid);
        return "redirect:/comment/getCommentAll";
    }

//    删

    //    根据id删除指定的评论
    @RequestMapping("/deleteCommentById")
    public String deleteCommentById(Integer id) {
        System.out.println("=======deleteCommentById========");
        contentService.deleteCommentById(id);
        return "redirect:/comment/getCommentAll";
    }
//    查


    //    查询所有社团信息
//    @RequestMapping("/getAllClub")
//    public String getAllUser(@RequestParam(defaultValue = "1") Integer currentPage,
//                             @RequestParam(defaultValue = "5") Integer pageSize,
//                             HttpServletRequest request,
//                             HttpSession session) {
//        System.out.println("=========getAllClub====================");
//        System.out.println("currentPage = " + currentPage);
////        创建pages对象
//        Pages pages = new Pages();
////        设置当前页
//        pages.setCurrentPage(currentPage);
////        设置页面容量
//        pages.setPageSize(pageSize);
////        设置总记录数
//        pages.setTotalCount(clubService.count());
////        将pages对象保存到request中
//        request.setAttribute("ClubPages", pages);
////        分页查询
//        List<Club> list = clubService.getAllClub(currentPage, pageSize);
////        将集合保存到request
//        request.setAttribute("ClubList", list);
//
////        return "redirect:clubBackground";
//        return "clubBackground";
//    }


}
